$(function() {
	$("#left").load("../../page/common/left.html");
	var deptId;
	var serId;
	var usertype1 = 1;
	v_list = new Vue({
		el: '#complain-index',
		data: {
			dto: {
				userId: '',
				mobile: '',
				name: '',
				sex: '',
				nation: '',
				birthday: '',
				address: '',
				cardNum: '',
				issued: '',
				life: ''
			},
			deptId: '',
			serId: '',
			theme: '',
			content: '',
			deptList: [],
			serList: [],
			itemsList: []
		},
		methods: {
			//原先
			getDeptList: function() {
				this.$http.get(gover.getDeptList, {}).then(function(res) {
					//接收后端传来的数据
					
					console.log(toJson(res.data.data));
					if(res.data.success) {
						this.deptList = res.data.data;
					}else{
						showRedMsg("message", "抱歉，服务器偷懒了~");
					}
				}, function(res) {
					console.log("获取部门出错:" + toJson(res));
					showRedMsg("message", "抱歉，服务器偷懒了~");
				});
			},
			getItemsList: function(deptId) {
				this.$http.get(gover.getItemsList, {
					businessId: deptId,
					type: 'dept'
				}).then(function(res) {
					//接收后端传来的数据
					console.log(toJson(res.data));
					if(res.data.success) {
						this.serId ="02"
						this.itemsList = res.data.data.itemsList;
					}else{
						this.serId ="02"
						this.itemsList = null;
						showRedMsg("message", "抱歉，该部门下没有事项!~");
					}
				}, function(res) {
					console.log("获取事项列表出错:" + toJson(res));
					showRedMsg("message", "抱歉，服务器偷懒了~");
				});
			},
			save: function() {
				if(this.theme == '') {
					showRedMsg("message", "请填写投诉主题!");
					return false;
				} else if(this.theme.trim() == '') {
					showRedMsg("message", "请填写投诉主题!");
					return false;
				}
				if(this.content == '') {
					showRedMsg("message", "请填写投诉内容!");
					return false;
				} else if(this.content.trim() == '') {
					showRedMsg("message", "请填写投诉内容!");
					return false;
				}
				this.$http.post(complain.saveComplain, {
					type: "1",
					userId: this.dto.userId,
					deptId: this.deptId,
					serId: this.serId,
					theme: this.theme,
					content: this.content
				}, {
					emulateJSON: true
				}).then(function(res) {
					//接收后端传来的数据
					doMask()
					console.log(toJson(res.data));
					if(res.data.success) {
						unMask();
						window.location = "complain-result.html"
					} else {
						unMask();
						showRedMsg("message", "保存出错");
					}
				}, function(res) {
					unMask();
					showRedMsg("message", "保存出错");
					console.log("保存出错:" + toJson(res));
				});
			},
			changetype1: function(value) {
				if(usertype1 != value) {
					$("#selectrd_xx1").css("display", "none");
					$("#sx").addClass("dis_no")

				} else {
					$("#selectrd_xx1").css("display", "block");
					$("#sx").removeClass("dis_no")

				}
				usertype = value;
			},
			changetype2: function(value) {
				if(usertype1 != value) {
					$("#selectrd_xx2").css("display", "none")
				} else {
					$("#selectrd_xx2").css("display", "block");
					this.getItemsList(this.deptId)
				}
				usertype = value;
			},
			deptChange: function() {
				this.getItemsList(this.deptId)
			},
			//常用

			//常用结束
		},
		filters: {
			titlefilter: function(val) {
				if(val != null && val.length > 43)
					val = val.substring(0, 42) + '...';
				return val;
			}
		},
		ready: function() {
			//初始化获得总页面数和列表数据
			this.dto = toObj(sessionStorage.getItem("dto"));
			var url="../up/index.html";
			windowOpen(url);
			this.getDeptList();
		}
	});
});